<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>银行卡绑定</title>
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/bui.css" />
</head>
<body>
<style type="text/css">
    .personal-header {
        margin-top: 10px;
        margin-left: 5px;
        margin-right: 5px;
        border-radius: 10px;
        background-color: #39a4ff;
        /*background-image: linear-gradient(to bottom, #7cb8e9, #89bfe3, #72a8d7, #89b5d8, #92bbda);*/
        padding-top: .3rem;
        padding-bottom: .3rem;
    }

    .personal-header .personal-img {
        width: 1.5rem;
        height: 1.5rem;
        border-radius: 50%;
        /*background:#fff;*/
        /* border: 2px solid #fff; */
        overflow: hidden;
        margin: 0 auto .2rem auto;
        text-align: center;
    }

    .personal-header .personal-img img {
        width: 100%;
    }

    .personal-header p {
        text-align: center;
        color: #ffffff;
        margin-bottom: 0.1rem;
    }

    .personal-header .name {
        font-size: 0.26rem;
    }

    .personal-header .grade {
        font-size: 0.2rem;
    }

    .nav-list {
        border-top: none;
        margin-top: 0.2rem;
        padding: 0 0.2rem;
        background-color: #ffffff;
    }

    .nav-list .bui-btn {
        padding-left: 0;
        padding-right: 0;
    }

    .nav-list li:first-child {
        border-top: none;
    }

    .nav-list .icon i {
        font-size: 0.4rem;
    }

    .nav-list .icon {
        height: 0.42rem;
    }

    .nav-list .bui-btn {
        border: none;
        border-top: 1px solid #efefef;
    }

    .icon-yellow {
        color: #ffad03;
    }

    .icon-thinblue {
        color: #56ced5;
    }

    .icon-green {
        color: #6ed046;
    }

    .icon-red {
        color: #fd8886;
    }
    .main-footer {
        background-color: #fff
    }

    .main-footer .btn-home {
        position: relative;
        overflow: visible
    }

    .main-footer .btn-home .big-icon {
        z-index: 10;
        margin-top: -.2rem;
        display: inline-block;
        width: .94rem;
        height: .94rem;
        line-height: .94rem;
        color: #fff;
        border-radius: 50%;
        background: linear-gradient(141.4deg, #02b9fa, #508dff)
    }
    .main-footer .layer1 {
        top: -.3rem;
        left: 50%;
        width: 1.2rem;
        height: 1.2rem;
        position: absolute;
        box-shadow: 0 0 1px 1px #eee;
        border-radius: 50%;
        transform: translateX(-50%);
        background-color: #fff
    }

    .main-footer .layer2 {
        position: absolute;
        top: 0rem;
        bottom: -.05rem;
        width: 100%;
        background-color: #fff
    }
</style>

<div class="bui-page">
    <header class="bui-bar">
        <div class="bui-bar-left">
            <a class="bui-btn btn-back" href="./my.html"><i class="icon-back"></i></a>
        </div>
        <div class="bui-bar-main">银行卡管理</div>
        <div class="bui-bar-right">
            <a class="bui-btn" id="bindBtn">绑定</a>
        </div>
    </header>
    <main>
        <div id="listview" style="display: none">

        </div>

    </main>

</div>

    <!-- 依赖库 手机调试的js引用顺序如下 -->
    <script src="../js/zepto.js"></script>
    <script src="../js/plugins/fastclick.js"></script>
    <script src="../js/bui.js"></script>
    <script src="../js/common.js"></script>
    <script>
        var yhkh = null;

        var user;

        function unbindBank (memberacctno,bindcardno,yhdm) {
            bui.confirm("确定要解绑银行卡么？", function(e) {
                var text = $(e.target).text();
                if (text == "确定") {
                    //执行登录操作
                    // console.log("你点击了" + $(e.target).text());
                    if(yhdm!='' && yhdm){
                        //充值卡
                        var unbindAjax = bui.ajax({
                            url: BASE_URL+"ysksdk/backTrade/untyingBankCard?membercode="+$$("membercode")+"&bindcardno="+bindcardno,
                            method: "GET"
                        });
                        unbindAjax.then(function(res) {
                            if(res.TxnReturnCode=='T0000'){
                                bui.alert('解绑成功！', function(e){
                                    window.location.href = "bank.html";
                                });
                            }else{
                                bui.alert(res.TxnReturnMsg, function(e){
                                    window.location.href = "bank.html";
                                });
                            }

                            //TxnReturnCode: "T6524",TxnReturnMsg: "银行卡信息不存在"
                            //"TxnReturnCode":"T7614","TxnReturnMsg":"银行卡已解除绑定"
                            // if(res.TxnReturnCode == 'T7614'){
                            //     bui.alert(res.msg);
                            // }else{
                            //     bui.alert(res.msg);
                            // }
                        },function(res) {
                            bui.alert("请求异常");
                        })
                    }else{
                        //提现卡
                        var unbindAjax = bui.ajax({
                            url: BASE_URL+"pig/t-jzb-bindcard/jzbunbinddard",
                            data:{
                                subacctno:user.subno,
                                trannetmembercode:user.membercode,
                                memberacctno:memberacctno,
                            },
                            method: "POST"
                        });
                        unbindAjax.then(function(res) {
                            bui.alert(res.message, function(e){
                                window.location.href = "bank.html";
                            });

                        },function(res) {
                            bui.alert("请求异常");
                        })
                    }


                }
                this.close()
            });
        }

        bui.ready(function () {
            initCommon(bui);
            user = $$("user");
            var storage = bui.storage();

            // 这里写业务及控件初始化
            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();

            var uiActionsheet = bui.actionsheet({
                trigger: "#bindBtn",
                buttons: [{ name: "充值银行卡", value: "cz" }, { name: "提现银行卡", value: "tx" }],
                callback: todo
            })

            // var uiActionsheet = bui.actionsheet({
            //     trigger: "#btnOpen",
            //     buttons: [{ name: "绑定充值银行卡", value: "cz" }, { name: "绑定提现银行卡", value: "tx" }],
            //     callback: todo
            // })

            function todo(e) {
                var val = $(e.target).attr("value");
                if (val == "cancel") {
                    this.hide();
                }else if(val == "cz"){
                    // bui.alert("绑定充值银行卡");
                    window.location.href = "/ysksdk/bindCard?membercode="+$$("membercode");
                }else if(val == "tx"){
                    // bui.alert("绑定提现银行卡");
                    // uiActionsheet.hide();

                    window.location.href = "bindtx.html";
                }
            }

            var yhbm = $$("yhbm");

            var versionAjax = bui.ajax({
                url: BASE_URL+"front/banklist?yhbm="+yhbm,
                method: "GET"
            });
            versionAjax.then(function(res) {
                if(res.code == 0){
                    var list  = res.data;
                    if(list){
                        $("#listview").show();
                        $("#listview").html("");
                        for (let i = 0; i < list.length; i++) {
                            var record = list[i];
                            if(record.YHKH != null && record.YHKH != ""){
                                yhkh = record.YHKH;
                                var yhklx='';
                                if(record.YHDM!='' && record.YHDM){
                                    yhklx='<span style="color: red;margin-left: 20px">充值卡</span>';
                                }else{
                                    yhklx='<span style="color: yellow;margin-left: 20px">提现卡</span>';
                                }

                                var html = `
                                <div class="personal-header" >
                                    <div style="color: white;margin-left: 10px" id="yhmc">
                                        `+$$$(record.YHMC)+yhklx+`
                                    </div>
                                    <div class="bui-box-align-middle" style="color: white;margin-left: 10px;margin-top: 10px" id="yhkh">
                                        <div class="span3">
                                            <h3><strong>`+$$$(record.YHKH)+`</strong></h3>
                                        </div>
                                        <div class="span1">
                                            <input type="button" id="unbind" style="width: 80px;color: black;font-size: .27rem" value="解绑" onclick="unbindBank('`+$$$(record.YHKH)+`','`+$$$(record.BINDCARDNO)+`','`+$$$(record.YHDM)+`')"/>
                                        </div>
                                    </div>
                                </div>
                            `;
                                $("#listview").append(html);
                            }
                        }
                    }
                }else{
                    bui.alert(res.msg);
                }
            },function(res) {
                bui.alert("请求异常");
            })


        })
    </script>
</body>
</html>